//
//  MCLoginPasswordCollectionViewCell.m
//  TLYL
//
//  Created by MC on 2017/7/11.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCLoginPasswordCollectionViewCell.h"

#define HEIGHT_LINE 50

@interface MCLoginPasswordCollectionViewCell()

/*
 * 打底
 */
@property (nonatomic,strong)UIView * view_back;

/*
 * 旧密码
 */
@property (nonatomic,strong)UITextField * textField_oldPassWord;
@property (nonatomic,strong)UIView * view_line1;

/*
 * 新密码
 */
@property (nonatomic,strong)UITextField * textField_newPassWord;
@property (nonatomic,strong)UIView * view_line2;

/*
 * 确认新密码
 */
@property (nonatomic,strong)UITextField * textField_affirmNewPassWord;


/*
 * 确定
 */
@property (nonatomic,strong)UIButton * btn_OK;
@end

@implementation MCLoginPasswordCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self){
        [self initView];
    }
    return self;
}

-(void)setDataSource:(id)dataSource{
    _dataSource=dataSource;
    _lab_title.text =dataSource;
}

- (void)initView{
    
    self.backgroundColor=[UIColor clearColor];
    
    
    /*
     * 打底
     */
    _view_back=[[UIView alloc]init];
    [self addSubview:_view_back];
    _view_back.backgroundColor=[UIColor whiteColor];
    _view_back.layer.cornerRadius=5;
    _view_back.clipsToBounds=YES;
    _view_back.layer.borderColor = RGB(200, 200, 200).CGColor;
    _view_back.layer.borderWidth = 0.5;
    _view_back.frame=CGRectMake(10, 20, G_SCREENWIDTH-20, 150);
    
    
    
    /*
     * 旧密码
     */
    _textField_oldPassWord = [[UITextField alloc] init];
    [self setTextField:_textField_oldPassWord WithPlaceholder:@"请输入旧登录密码" and:UIKeyboardTypeDefault];
    
    [_textField_oldPassWord mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_view_back.mas_top).offset(0);
        make.left.equalTo(_view_back.mas_left).offset(0);
        make.right.equalTo(_view_back.mas_right).offset(0);
        make.height.mas_equalTo(HEIGHT_LINE);
    }];
    
    
    
    
    _view_line1=[[UIView alloc]init];
    [_view_back addSubview:_view_line1];
    _view_line1.backgroundColor=RGB(200, 200, 200);
    _view_line1.frame=CGRectMake(0, HEIGHT_LINE, G_SCREENWIDTH, 0.5);
    
    
    
    /*
     * 新资金密码
     */
    _textField_newPassWord=[[UITextField alloc] init];
    [self setTextField:_textField_newPassWord WithPlaceholder:@"请输入新登录密码" and:UIKeyboardTypeDefault];
    
    [_textField_newPassWord mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_view_line1.mas_bottom).offset(0);
        make.left.equalTo(_view_back.mas_left).offset(0);
        make.right.equalTo(_view_back.mas_right).offset(0);
        make.height.mas_equalTo(HEIGHT_LINE);
    }];
    
    _view_line2=[[UIView alloc]init];
    [_view_back addSubview:_view_line2];
    _view_line2.backgroundColor=RGB(200, 200, 200);
    _view_line2.frame=CGRectMake(0, HEIGHT_LINE*2, G_SCREENWIDTH, 0.5);
    
    
    /*
     * 确认新资金密码
     */
    _textField_affirmNewPassWord=[[UITextField alloc] init];
    [self setTextField:_textField_affirmNewPassWord WithPlaceholder:@"请确认新登录密码" and:UIKeyboardTypeDefault];
    
    [_textField_affirmNewPassWord mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_view_line2.mas_bottom).offset(0);
        make.left.equalTo(_view_back.mas_left).offset(0);
        make.right.equalTo(_view_back.mas_right).offset(0);
        make.height.mas_equalTo(HEIGHT_LINE);
    }];
    
    
    //添加
    _btn_OK=[[UIButton alloc]init];
    [_btn_OK setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_btn_OK setImage:[UIImage imageNamed:@"MCUserDefined_Sure"] forState:UIControlStateNormal];
    _btn_OK.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    _btn_OK.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    [_btn_OK setBackgroundColor:RGB(69, 146, 225)];
    [self addSubview:_btn_OK];
    [_btn_OK addTarget:self action:@selector(action_Add) forControlEvents:UIControlEventTouchUpInside];
    _btn_OK.layer.cornerRadius=25.0;
    _btn_OK.clipsToBounds=YES;
    
    [_btn_OK mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(40);
        make.right.equalTo(self.mas_right).offset(-40);
        make.top.equalTo(_view_back.mas_bottom).offset(50);
        make.height.mas_equalTo(50);
    }];
    
    UILabel * lab_tip=[[UILabel alloc]init];
    lab_tip.font=[UIFont systemFontOfSize:12];
    lab_tip.textColor=RGB(100, 100, 100);
    [self addSubview:lab_tip];
    lab_tip.text=@"*6-16位字符，可以使用字母或数字";
    lab_tip.textAlignment=NSTextAlignmentCenter;
    [lab_tip mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(0);
        make.right.equalTo(self.mas_right).offset(0);
        make.bottom.equalTo(self.mas_bottom).offset(-10);
    }];
    
}
-(void)textFieldDidChange:(UITextField *)textField{
    if (textField.text.length>15) {
        textField.text =  [textField.text substringToIndex:16];
    }
}


-(void)setTextField:(UITextField*)textField WithPlaceholder:(NSString *)placeholder and:(UIKeyboardType)type{
    textField.placeholder=placeholder;
    textField.borderStyle = UITextBorderStyleNone;
    textField.backgroundColor=[UIColor whiteColor];
    textField.font = [UIFont systemFontOfSize:15];
    textField.textColor = RGB(100, 100, 100);
    textField.textAlignment = NSTextAlignmentCenter;
    textField.returnKeyType = UIReturnKeyDone;
    textField.keyboardType = type;
    [textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:(UIControlEventEditingChanged)];
    [_view_back addSubview:textField];
    
}






/*
 * 添加
 */
-(void)action_Add{
    if (_textField_oldPassWord.text.length<6||_textField_newPassWord.text.length<6||_textField_affirmNewPassWord.text.length<6) {
        [MBProgressHUD showError:@"密码长度不能少于6位"];
        return;
    }
    //    if ([self.delegate respondsToSelector:@selector(MCAddBankCardFooter_Add)]) {
    //        [self.delegate MCAddBankCardFooter_Add];
    //    }
    
}



@end
